home *** CD-ROM | disk | FTP | other *** search
- Path: iz.maus.de!Torsten_Landschoff
- From: Torsten_Landschoff@iz.maus.de (Torsten Landschoff)
- Newsgroups: comp.lang.c++
- Subject: Can copy constructor and operator= share code?
- Message-ID: <199603040709.a35476@iz.maus.de>
- Date: Mon, 04 Mar 96 05:09:00 GMT
- References: <4h2kcn$40d@rap.SanDiegoCA.ATTGIS.COM>
- X-Gate: MausGate/News 1.25/ac3
- MIME-Version: 1.0
- Content-Type: text/plain; charset=ISO-8859-1
- Content-Transfer-Encoding: 8bit
-
- -A13545@AC3
-
- Hi Boris
-
- BB>I have tried calling the copy constructor from operator=, but nothing
- BB>happens. I've gotten around this problem by creating a private Copy()
- BB>function, which is called by both the copy constructor and operator=.
- BB>Is there another way?
-
- This is the wrong way round but you can call the operator = from the copy
- constructor:
-
- class A {
- ...
- public:
- A &operator =(const A &); // declare the assignment operator
- A( const A &src ) {
- *this = src; // call the assignment operator
- }
- };
-
- Hope it helps
- Torsten
-